/*
 * Copyright (C) 2011, EADS France
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */
package xowl.gmi.model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import xowl.utils.config.Configuration;

/**
 *
 * @author Laurent WOUTERS
 */
public class Project {
    private String name;
    private String file;
    private List<Diagram> diagrams;
    
    public String getName() { return name; }
    public String getFile() { return file ;}
    public Collection<Diagram> getDiagrams() { return diagrams; }
    public void addDiagram(Diagram diagram) { diagrams.add(diagram); }
    public void removeDiagram(Diagram diagram) { diagrams.remove(diagram); }
    
    public Project(String name, String file) {
        this.name = name;
        this.file = file;
        this.diagrams = new ArrayList<>();
    }
    
    public Project(Configuration config, Workbench workbench) {
        this.name = config.getValue("name");
        this.file = config.getValue("file");
        this.diagrams = new ArrayList<>();
        for (String diagram : config.getValues(null, "diagram"))
            this.diagrams.add(new Diagram(diagram, config, workbench));
    }
    
    public void save(Configuration config) {
        config.addValue(null, "name", name);
        config.addValue(null, "file", file);
        for (Diagram diagram : diagrams) {
            config.addValue(null, "diagram", diagram.getID());
            diagram.save(config);
        }
    }
}
